package com.ninthgroup.service.Impl;

import com.ninthgroup.entity.Scheduling;
import com.ninthgroup.mapper.SchedulingMapper;
import com.ninthgroup.service.SchedulingService;
import com.ninthgroup.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * @author ：1452863884@qq.com rcg
 * @date ：Created in 2022/10/20 15:51
 * @description：排班管理的接口的实现
 * @modified By：
 * @version:1.0
 */
@Service
public class SchedulingServiceImpl implements SchedulingService {

    @Autowired
    private SchedulingMapper schedulingMapper;


    @Override
    public Result selectAll() {
        List<Scheduling> schedulings = schedulingMapper.selectAllSchedulingDoctor();
        return new Result(200,"查询所有已经排完班的医生",schedulings);
    }

    @Override
    public Result findOne(Integer sDid) {
        return null;
    }

    @Override
    public Result updateScheduling(Scheduling scheduling) {

        int i = schedulingMapper.updateByPrimaryKeySelective(scheduling);
        return new Result(200,"修改排班成功");
    }

    @Override
    public Result add(Scheduling scheduling) {
        int i = schedulingMapper.insertSelective(scheduling);
        return new Result(200,"排班成功");

    }

    @Override
    public Result selectOne(Integer sDid) {
        List<Scheduling> schedulings = schedulingMapper.selectByDid(sDid);

        return   new Result(200,"成功",schedulings);

    }

    @Override
    public Result lessNum(Scheduling scheduling) {
        //获取时间找到对应的排班医生
        Date date = scheduling.getsDate();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String format = simpleDateFormat.format(date);
        Scheduling scheduling1 = schedulingMapper.lessNum(format);

        //修改数量
        Integer integer = scheduling1.getsNum();
        scheduling1.setsNum(integer-1);
        schedulingMapper.updateByPrimaryKeySelective(scheduling1);
        return new Result(200,"修改成功");
    }
}